package com.google.blockly.ohos.demo.view;

import com.google.blockly.ohos.ResourceTable;
import com.google.blockly.ohos.demo.EventHelper;
import com.google.blockly.ohos.demo.SimpleAbility;
import com.google.blockly.ohos.ui.CategoryTabs;
import com.google.blockly.ohos.ui.TextVertical;
import ohos.agp.components.Button;
import ohos.agp.components.Image;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class SimpleAbilityTest {

    private SimpleAbility ability;

    @Before
    public void setUp() throws Exception {
        ability = EventHelper.startAbility(SimpleAbility.class);
    }

    @After
    public void tearDown() throws Exception {
        EventHelper.clearAbilities();
    }

    @Test
    public void clickMore() throws Exception {
        Image image = (Image) ability.findComponentById(ResourceTable.Id_action_more);
        EventHelper.triggerClickEvent(ability, image);
        Thread.sleep(1000);
        Assert.assertNotNull("It's right", image);
    }

    @Test
    public void clickblockly_zoom_in() throws Exception {
        Button button = (Button) ability.findComponentById(ResourceTable.Id_blockly_zoom_in_button);
        EventHelper.triggerClickEvent(ability, button);
        Thread.sleep(1000);
        Assert.assertNotNull("It's right", button);
    }

    @Test
    public void clickblockly_zoom_out() throws Exception {
        Button button = (Button) ability.findComponentById(ResourceTable.Id_blockly_zoom_out_button);
        EventHelper.triggerClickEvent(ability, button);
        Thread.sleep(1000);
        Assert.assertNotNull("It's right", button);
    }

    @Test
    public void clickblockly_center() throws Exception {
        Button button = (Button) ability.findComponentById(ResourceTable.Id_blockly_center_view_button);
        EventHelper.triggerClickEvent(ability, button);
        Thread.sleep(1000);
        Assert.assertNotNull("It's right", button);
    }

    @Test
    public void clickAction_save() throws Exception {
        Image image = (Image) ability.findComponentById(ResourceTable.Id_action_save);
        EventHelper.triggerClickEvent(ability, image);
        Thread.sleep(1000);
        Assert.assertNotNull("It's right", image);
    }

    @Test
    public void clickAction_load() throws Exception {
        Image image = (Image) ability.findComponentById(ResourceTable.Id_action_load);
        EventHelper.triggerClickEvent(ability, image);
        Thread.sleep(1000);
        Assert.assertNotNull("It's right", image);
    }

    @Test
    public void clickCategory_tabs() throws Exception {
        CategoryTabs categoryTabs = (CategoryTabs) ability.findComponentById(ResourceTable.Id_category_tabs);
        TextVertical textVertical = (TextVertical) categoryTabs.getComponentAt(0);
        EventHelper.triggerClickEvent(ability, textVertical);
        Thread.sleep(5000);
        Assert.assertNotNull("It's right", categoryTabs);
    }

}